package com.atguigu.paymentdemo.controller;


import com.atguigu.paymentdemo.enums.OrderStatus;
import com.atguigu.paymentdemo.service.OrderInfoService;
import com.atguigu.paymentdemo.vo.R;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@CrossOrigin//开放前端跨域

@RestController//对于负责Restful API交互的功能模块,该类中所有的API接口返回的数据，
// 甭管返回Map或是其他Object，都以Json字符串的形式返回给客户端
@RequestMapping("api/order-info")
@Api(tags="订单管理")
public class OrderInfoController {
    @Resource
    OrderInfoService orderInfoService;

    @GetMapping("/list")
    public R list(){
        return R.ok().data("list",orderInfoService.listDescTimeStamp());
    }

    @GetMapping("query-order-status/{orderNo}")
    public R queryOrderStatus(@PathVariable String orderNo){

        if(orderInfoService.queryTradeState(orderNo).equals(OrderStatus.SUCCESS.getType()))
            return R.ok().setMessage("支付成功");//支付成功

        return R.ok().setCode(101).setMessage("支付中");

    }

}
